#include <iostream>
using namespace std;
class Stripe{
private:
    int Ncolor;
    int Nfav;//number of favorite sequence
    int fav[205];
    int Nstripe;
    int stripe[10005];
public:
    Stripe(int _Ncolor){
	Ncolor=_Ncolor;
    }
    void set_fav(){
	cin>>Nfav;
	for(int i=0;i<Nfav;i++){
	    cin>>fav[i];
	}
    }
    void set_stripe(){
	cin>>Nstripe;
	for(int i=0;i<Nstripe;i++){
	    cin>>stripe[i];
	}
    }
    int get_fav(){
	return Nfav;
    }
    int get_stripe(){
	return Nstripe;
    }
    int get_maxlen(int Lfav,int Lstripe);
    int max(int a,int b){
	if(a>b){
	    return a;
	}else{
	    return b;
	}
    }
};
int Stripe::get_maxlen(int Lfav,int Lstripe){
    int num=0;
    if(Lfav==0){//case1:favorite sequence has only 1 type
	for(int i=0;i<=Lstripe;i++){
	    if(fav[0]==stripe[i]){
		num++;
	    }
	}
	return num;
    }
    else if(Lstripe==-1){//case2:can't find its formal node
	return 0;
    }else{
	int formalfav=fav[Lfav-1];
	int newstripe;
	int j;
	for(j=Lstripe;j>=0;j--){
	    if(stripe[j]==formalfav){
		break;
	    }
	}
	newstripe=j;
	for(j=newstripe+1;j<=Lstripe;j++){
	    if(stripe[j]==fav[Lfav]){
		num++;
	    }
	}
	return max((get_maxlen(Lfav-1,newstripe)+num),get_maxlen(Lfav-1,Lstripe));
    }
};
int main(){
    int Ncolor;
    cin>>Ncolor;
    Stripe S(Ncolor);
    S.set_fav();
    S.set_stripe();
    int result=S.get_maxlen(S.get_fav()-1,S.get_stripe()-1);
    cout<<result<<endl;
}
